import { postRequest, postRequestJson, getRequest  } from '../api.js';

export default {

    //查询可购买钓场
    async queryNearbyBasanList({ date, latitude, longitude }) {
        let url = '/api/fishery/queryAnglingsiteByLonlat';
        const params = {
            date: date + ' 08:00:00',
            latitude,
            longitude
        }
        return new Promise((resolve, reject) => {
            postRequestJson(url, params).then(res => {
                resolve(res);
            });
        });
    },

    async queryCollectedBasanList({ }) {
        let url = '/api/elfFavoriteFishspots/getPageList';
        const params = {
            pageIndex: 0,
            pageSize: 200,
        }
        return new Promise((resolve, reject) => {
            postRequestJson(url, params).then(res => {
                resolve(res);
            });
        });
    },

    async addCollectedBasan({ userId, lat, lng }) {
        let url = '/api/elfFavoriteFishspots/add';
        const params = {
            userId,
            lat,
            lng
        }
        return new Promise((resolve, reject) => {
            postRequestJson(url, params).then(res => {
                resolve(res);
            });
        });
    },

    async removeCollectedBasan({ id }) {
        let url = '/api/elfFavoriteFishspots/delete'
        const params = {
            id
        };
        return new Promise((resolve, reject) => {
            postRequestJson(url, params).then(res => {
                resolve(res);
            });
        });
    },
    
    async fetchBasanInfo({ basanId }) {
        let url = `/api/fishery/info/geojson/${basanId}`;
        return new Promise((resolve, reject) => {
            getRequest(url).then(res => {
                res.basan = res.data.features[0];
                resolve(res);
            });
        });
    },
}